<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<div id="container"></div>
		<script src="../jslib/mustache.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			var templateStr = "今天我买了一个{{thing}}，花了{{money}}元,感觉好{{mood}}"
			var data ={
				thing:'白菜',
				money:5,
				mood:'好开心'
			}
			
			/*
			*简单替换模板字符的方法
			* str 传入的模板字符串
			* data 要替换的数据
			*/
		   function replaceStr(str,data) {
			   return str.replace(/\{\{(\w+)\}\}/g,(findStr,n,y,s) => {
				   /*
				   *param findstr 匹配到的字符串
				   * n 双括号内的内容
				   * y 匹配到的位置
				   * s 输入的整个字符串
				   */
				   return data[n]
			   })
		   }
		   
		  var domStr =  replaceStr(templateStr,data)
		   
		   //上树
		   var container = document.getElementById('container')
		   container.innerHTML = domStr
		</script>
	</body>
</html>
